<template>
  <div style="display: flex;flex-direction: column;align-items: center;justify-content: center;">
    <el-card class="info-card">
      <template #header>
        <h2 style="text-align: left;margin:20px">我的班课</h2>
      </template>
      <div>
        <ClassCardList />
      </div>
    </el-card>
  </div>
</template>


<script lang="ts" setup>
import ClassCardList from "@/views/main/teacher/home/classCardList.vue"
import { onActivated ,onMounted } from "vue";
import { getMyCourseListApi } from '@/api/course'
import { useStore } from 'vuex'
import { detectAccountInfoApi } from '@/api/user'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
const router = useRouter()
onMounted(() => {
  detectAccountInfoApi({
    user_id: store.state.user.user_id,
    is_teacher: store.state.user.is_teacher,
    is_super: false
  }).then((res: any) => {

    if (res.code === 200) {
      if (res.data.code === 1) {
        // 提醒修改密码，并显示跳转链接
        ElMessageBox.confirm(res.data.msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            router.push({ path: '/student/info', state: {activeName : 'changePassword' } })

          }
          )
      }
    }
  })
})
const store = useStore()
onActivated(() => {
  if(history.state.back!==null)
    getMyCourseListApi({
      user_id: store.state.user.user_id,
      is_teacher: store.state.user.is_teacher,
      page: 1,
      pageSize: 50,
    }).then((res: any) => {
      if (res.code === 200) {
        if (store.state.user.courseCount !== res.data.pager.total) {
          store.commit('user/updateCourseCount', res.data.pager.total)
          setTimeout(() => {
            location.reload()
          }, 50)
        }
      }
    })
})

</script>


<style lang="scss" scoped>
.info-card {
  position: relative;
  width: 100vw;
  max-width: 1500px;
  height: auto;
  // max-height: 600px;

  align-content: center;
  margin-top: 10px;
}
</style>